<template>
  <el-form label-position="top"
           :model="data"
           ref="form"
           style="margin: 10px; width: auto"
  >
    <el-form-item prop="qtType" label="班次名称" class="form_item_label">
      <el-input v-model="data.shiftName"></el-input>
    </el-form-item>
    <el-form-item prop="qtType" label="班次时间(天)" class="form_item_label">
      <el-input v-model="data.useDays"></el-input>
    </el-form-item>
    <el-form-item>
      <div class="w_full flex-row-center center-center" style="margin-top: 32px;">
        <el-button type="primary" @click="click_ok">确定</el-button>
      </div>
    </el-form-item>
  </el-form>
</template>


<script setup lang="ts">
import {reactive} from "vue";
import {useRoute} from "vue-router";
import msg from "@/components/msg";
import {ScheduleShiftVO} from "@/type/vo/ScheduleShiftVO";
import {api_addScheduleType} from "@/request/apis/shiftTypeApi";
import {api_addScheduleShift} from "@/request/apis/shiftApi";

const route = useRoute();
console.log(route);

const props = defineProps<{
  officeCode: string;
  shiftTypeId: string;
}>();

const emit = defineEmits(["close"])


const data = reactive({
      shiftName: '',
      useDays: 0,
    }
);

const click_ok = async () => {
  if (data.shiftName.length == 0) {
    await msg.info('请输入名称');
    return;
  }

  const schedule: ScheduleShiftVO =
      {
        createTime: 0,
        scheduleShiftId: "",
        showColor: 0,
        useDay: 0,
        scheduleShiftName: data.shiftName,
        index: 0,
        scheduleTypeId: props.shiftTypeId,
        officeCode: props.officeCode
      }

  const r = await api_addScheduleShift(schedule);
  if (!r) {
    await msg.error("数据异常");
    return;
  }
  if (r.code != 0) {
    await msg.error(`数据异常!  ${r.code} msg：${r.msg}`);
    return;
  }

  emit("close", true);
}

const click_cancel = () => {
  emit("close", false);
}


</script>

<style scoped>
.item .el-form-item__label {
  font-size: 14px;
  font-weight: 400;
  color: #7D8592;
  line-height: 24px;
}

</style>